In [57]:
workspace()
z = begin
x = 1
y = 2
x + y
end
println(z)
#using the (;) chain syntax
y = begin x = 1; y = 2; x + y end
println(y)
In [58]:
a = 3
b = 4
if a < b
println("a is less than b")
elseif a > b
println("a is greater than b")
else
println("a is equal to b")
end
In [59]:
workspace()
t(x) = (println(x); true)
f(x) = (println(x); false)
t(4) || f(1)
# As the first function returns a true value, the statment is true, so it stops evaluating
Out[59]:
In [60]:
i = 1
while i <= 5
println(i)
i += 1
end
In [61]:
j=1
while true
println(j)
if j >= 5
break
end
j += 1
end
In [62]:
for i = 1:5
println(i)
end
In [63]:
#you can use for to iterate over arrays
for i in [1,4,0]
println(i)
end
str1 ="Hello"
for j in str1
println(j)
end
In [64]:
workspace()
k(x) = try
sqrt(x)
catch
sqrt(complex(x, 0))
end
println(k(4))
k(-4)
Out[64]:
In [ ]:
In [ ]: